/*  1:   */ package nl.siegmann.epublib.viewer;
/*  2:   */ 
/*  3:   */ import java.util.ArrayList;
/*  4:   */ import java.util.List;
/*  5:   */ import javax.swing.JScrollPane;
/*  6:   */ import javax.swing.JTable;
/*  7:   */ import javax.swing.JViewport;
/*  8:   */ import javax.swing.ListSelectionModel;
/*  9:   */ import javax.swing.event.ListSelectionEvent;
/* 10:   */ import javax.swing.event.ListSelectionListener;
/* 11:   */ import nl.siegmann.epublib.browsersupport.NavigationEvent;
/* 12:   */ import nl.siegmann.epublib.browsersupport.NavigationEventListener;
/* 13:   */ import nl.siegmann.epublib.browsersupport.Navigator;
/* 14:   */ import nl.siegmann.epublib.domain.Book;
/* 15:   */ import nl.siegmann.epublib.domain.Guide;
/* 16:   */ import nl.siegmann.epublib.domain.GuideReference;
/* 17:   */ 
/* 18:   */ public class GuidePane
/* 19:   */   extends JScrollPane
/* 20:   */   implements NavigationEventListener
/* 21:   */ {
/* 22:   */   private static final long serialVersionUID = -8988054938907109295L;
/* 23:   */   private Navigator navigator;
/* 24:   */   
/* 25:   */   public GuidePane(Navigator navigator)
/* 26:   */   {
/* 27:30 */     this.navigator = navigator;
/* 28:31 */     navigator.addNavigationEventListener(this);
/* 29:32 */     initBook(navigator.getBook());
/* 30:   */   }
/* 31:   */   
/* 32:   */   private void initBook(Book book)
/* 33:   */   {
/* 34:36 */     if (book == null) {
/* 35:37 */       return;
/* 36:   */     }
/* 37:39 */     getViewport().removeAll();
/* 38:40 */     JTable table = new JTable(createTableData(this.navigator.getBook().getGuide()), new String[] { "", "" });
/* 39:   */     
/* 40:   */ 
/* 41:   */ 
/* 42:44 */     table.setFillsViewportHeight(true);
/* 43:45 */     table.getSelectionModel().addListSelectionListener(new ListSelectionListener()
/* 44:   */     {
/* 45:   */       public void valueChanged(ListSelectionEvent e)
/* 46:   */       {
/* 47:49 */         if (GuidePane.this.navigator.getBook() == null) {
/* 48:50 */           return;
/* 49:   */         }
/* 50:52 */         int guideIndex = e.getFirstIndex();
/* 51:53 */         GuideReference guideReference = (GuideReference)GuidePane.this.navigator.getBook().getGuide().getReferences().get(guideIndex);
/* 52:54 */         GuidePane.this.navigator.gotoResource(guideReference.getResource(), GuidePane.this);
/* 53:   */       }
/* 54:56 */     });
/* 55:57 */     getViewport().add(table);
/* 56:   */   }
/* 57:   */   
/* 58:   */   private Object[][] createTableData(Guide guide)
/* 59:   */   {
/* 60:61 */     List<String[]> result = new ArrayList();
/* 61:62 */     for (GuideReference guideReference : guide.getReferences()) {
/* 62:63 */       result.add(new String[] { guideReference.getType(), guideReference.getTitle() });
/* 63:   */     }
/* 64:65 */     return (Object[][])result.toArray(new Object[result.size()][2]);
/* 65:   */   }
/* 66:   */   
/* 67:   */   public void navigationPerformed(NavigationEvent navigationEvent)
/* 68:   */   {
/* 69:70 */     if (navigationEvent.isBookChanged()) {
/* 70:71 */       initBook(navigationEvent.getCurrentBook());
/* 71:   */     }
/* 72:   */   }
/* 73:   */ }


/* Location:           C:\Users\David\workspace\CosaRaraPorqueSi\main\epublib-tools-3.1.jar
 * Qualified Name:     nl.siegmann.epublib.viewer.GuidePane
 * JD-Core Version:    0.7.0.1
 */